package com.hex.ds.hdtp.core.inf.script.test.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hex.ds.hdtp.core.inf.common.page.Page;
import com.hex.ds.hdtp.core.inf.common.page.converter.IPageAndMyBatisPlusPageConverter;
import com.hex.ds.hdtp.core.inf.script.test.mapper.IScriptDataTestResultMapper;
import com.hex.ds.hdtp.core.inf.script.test.po.ScriptDataTestResultPo;
import com.hex.ds.hdtp.core.inf.script.test.repository.IScriptDataTestResultRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Package: com.hex.ds.hdtp.core.inf.script.test.repository.impl
 * @ClassName ScriptDataTestResultRepository
 * @Description: 带数据脚本测试结果-数据接口实现
 * @Author: wz.li
 * @Date 2023/8/7 11:55
 * @Version v2.0.2
 **/
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ScriptDataTestResultRepository implements IScriptDataTestResultRepository {

    private final IScriptDataTestResultMapper scriptDataTestResultMapper;

    private final IPageAndMyBatisPlusPageConverter pageConverter;

    /*
     * @Method: queryConsanguinityListByPage <br>
     * @Param: [scriptDataTestResultPo, toPage] <br>
     * @Return: com.hex.ds.hdtp.core.inf.common.page.Page<com.hex.ds.hdtp.core.inf.script.test.po.ScriptDataTestResultPo> <br>
     * @Description：分页查询<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/7 11:55 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Page<ScriptDataTestResultPo> queryListByPage(ScriptDataTestResultPo scriptDataTestResultPo, Page toPage) {
        final IPage tmpPageResult = scriptDataTestResultMapper.queryListByPage(
                pageConverter.toMyBatisPlusPage(toPage)
                , scriptDataTestResultPo
        );
        final List list = tmpPageResult.getRecords();
        final Page pageResult = pageConverter.toPage(tmpPageResult);
        return pageResult.setData(list);
    }

    /*
     * @Method: queryList <br>
     * @Param: [batchCode, taskPkId] <br>
     * @Return: java.util.List<com.hex.ds.hdtp.core.inf.script.test.po.ScriptDataTestResultPo> <br>
     * @Description：不分页查询<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/7 15:14 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public List<ScriptDataTestResultPo> queryList(String batchCode, String taskPkId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("batch_code", batchCode);
        queryWrapper.eq("task_pk_id", taskPkId);
        return scriptDataTestResultMapper.selectList(queryWrapper);
    }


    /*
     * @Method: queryById <br>
     * @Param: [pkId] <br>
     * @Return: com.hex.ds.hdtp.core.inf.script.test.po.ScriptDataTestResultPo <br>
     * @Description：根据主键查询<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/7 11:55 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public ScriptDataTestResultPo queryById(String pkId) {
        return scriptDataTestResultMapper.selectById(pkId);
    }

    /*
     * @Method: add <br>
     * @Param: [scriptDataTestResultPo] <br>
     * @Return: java.lang.Integer <br>
     * @Description：新增<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/7 11:55 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer add(ScriptDataTestResultPo scriptDataTestResultPo) {
        return scriptDataTestResultMapper.insert(scriptDataTestResultPo);
    }

    /*
     * @Method: modifyById <br>
     * @Param: [scriptDataTestResultPo] <br>
     * @Return: java.lang.Integer <br>
     * @Description：根据主键更新<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/7 11:56 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer modifyById(ScriptDataTestResultPo scriptDataTestResultPo) {
        return scriptDataTestResultMapper.updateById(scriptDataTestResultPo);
    }

    /*
     * @Method: removeById <br>
     * @Param: [pkId] <br>
     * @Return: java.lang.Integer <br>
     * @Description：根据主键删除<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/7 11:56 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer removeById(String pkId) {
        return scriptDataTestResultMapper.deleteById(pkId);
    }
}
